package org.benjamin.lending.controller;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.benjamin.lending.domain.entity.MemberInfo;
import org.benjamin.lending.domain.form.MemberForm;
import org.benjamin.lending.service.MemberInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("manager/member")
public class ManagerMemberController {
	
	private Logger logger = LogManager.getLogger();
	
	@Autowired
	private MemberInfoService memberInfoService;
	
	@RequestMapping(value = "index")
	public ModelAndView index(MemberForm memberForm,Pageable pageable) {
		ModelAndView modelAndView = new ModelAndView("admin.member.index");
		Page<MemberInfo> memberInfos = this.memberInfoService.findMemberPage(memberForm,pageable);
		modelAndView.addObject("memberInfos",memberInfos);
		modelAndView.addObject("memberForm",memberForm);
		return modelAndView;
	}
	
	@RequestMapping(value = "details/{id}")
	public ModelAndView details(@PathVariable("id") Integer id) {
		ModelAndView modelAndView = new ModelAndView("admin/member/details");
		logger.info("查询用户详细信息");
		MemberInfo memberInfo = this.memberInfoService.findMemberDetails(id);
		modelAndView.addObject("memberInfo",memberInfo);
		return modelAndView;
	}

}
